#include <iostream>
#include <vector>

const int direction[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

bool dfs(std::vector<std::vector<char>> &res, int i, int j, int idx,
         std::vector<std::pair<int, int>> &coord, std::vector<std::vector<bool>> &visited, std::string targ_str)
{
    if (res[i][j] != targ_str[idx] || visited[i][j])
        return false;

    if (idx + 1 == targ_str.size())
    {
        coord.push_back({i, j});
        return true;
    }

    visited[i][j] = true;
    coord.push_back({i, j});

    for (int k = 0; k < 4; k++)
    {
        int x = j + direction[k][1];
        int y = i + direction[k][0];
        if (x < 0 || x >= res[0].size() || y < 0 || y >= res.size() || visited[y][x])
            continue;
        else if (dfs(res, y, x, idx + 1, coord, visited, targ_str))
            return true;
    }

    visited[i][j] = false;
    coord.pop_back();
    return false;
}

int main()
{
    int N;
    std::cin >> N;
    std::vector<std::vector<char>> res(N, std::vector<char>(N));

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            char c;
            std::cin >> c;
            res[i][j] = c;
            std::cin.ignore();
        }
    }
    std::string targ_str;
    std::cin >> targ_str;

    std::vector<std::vector<bool>> visited(N, std::vector<bool>(N, false));
    std::vector<std::pair<int, int>> coords;

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (dfs(res, i, j, 0, coords, visited, targ_str))
            {
                for (int m = 0; m < coords.size(); m++)
                {
                    if (m != 0)
                    {
                        std::cout << ",";
                    }
                    std::cout << coords[m].first << "," << coords[m].second;
                }
                std::cout << std::endl;
                return 0;
            }
        }
    }

    std::cout << "N" << std::endl;

    return 0;
}